<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252" %>
<!--#include file="common/connStr-s.asp" -->
<%

function Update() {
    var id = Request.Form("id");
    if (id == "" || id == 'undefined') {
        return;
    }
    var comObj = Server.CreateObject('ADODB.Command');
    
    var cmdStr = ""
    var title = Request.Form("title");
    var description = Request.Form("description");
    var albumId = Request.Form("albumId");
    var dateTaken = String(Request.Form("dateTaken"));
    
    //comObj.parameters.append(comObj.createParameter("@Title", adVarWChar, adParamInput, 128, title));
    comObj.parameters.append(comObj.createParameter("@Title", 202, 0x0001, 128, title));
    comObj.parameters.append(comObj.createParameter("@Description", 202, 0x0001, 2048, description));
    comObj.parameters.append(comObj.createParameter("@DateTaken", 7, 0x0001, 8, dateTaken));

    cmdStr = "UPDATE dbo.Photos SET Title=? , Description= ?, DateTaken= ?";
    if (albumId != "") {
        cmdStr += " ,AlbumId = ?"
        comObj.parameters.append(comObj.createParameter("@AlbumId", 3, 0x0001, 8, albumId));
    }
    comObj.parameters.append(comObj.createParameter("@PhotoID", 3, 0x0001, 8, id));
    cmdStr += " WHERE PhotoID = ?";

    comObj.CommandText = cmdStr;
    comObj.ActiveConnection = connStr;
    comObj.Execute();
    comObj.ActiveConnection.Close();
    delete comObj;
}
function Delete() {
    var id = Request.Form("id");
    if (id == "" || id == 'undefined' || id == undefined) {
        return;
    }
    var comObj = Server.CreateObject('ADODB.Command');
    
    var cmdStr = ""
    cmdStr = "DELETE FROM dbo.Photos WHERE PhotoID = ?";
    comObj.parameters.append(comObj.createParameter("@PhotoID", 3, 0x0001, 8, id));

    comObj.CommandText = cmdStr;
    comObj.ActiveConnection = connStr;
    comObj.Execute();
    comObj.ActiveConnection.Close();
    delete comObj;
}
var action = Request.Form("action")

if (action == 1) {
    Delete();
}    
if (action == 2) {
    Update();
}

%>